.TH std::atomic_is_lock_free,ATOMIC_xxx_LOCK_FREE 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::atomic_is_lock_free,ATOMIC_xxx_LOCK_FREE \- std::atomic_is_lock_free,ATOMIC_xxx_LOCK_FREE

.SH Synopsis
   Defined in header <atomic>
   template< class T >
   bool atomic_is_lock_free( const volatile std::atomic<T>* obj )     \fB(1)\fP \fI(since C++11)\fP
   noexcept;
   template< class T >                                                \fB(2)\fP \fI(since C++11)\fP
   bool atomic_is_lock_free( const std::atomic<T>* obj ) noexcept;
   #define ATOMIC_BOOL_LOCK_FREE     /* unspecified */

   #define ATOMIC_CHAR_LOCK_FREE     /* unspecified */
   #define ATOMIC_CHAR16_T_LOCK_FREE /* unspecified */
   #define ATOMIC_CHAR32_T_LOCK_FREE /* unspecified */
   #define ATOMIC_WCHAR_T_LOCK_FREE  /* unspecified */                \fB(3)\fP \fI(since C++11)\fP
   #define ATOMIC_SHORT_LOCK_FREE    /* unspecified */
   #define ATOMIC_INT_LOCK_FREE      /* unspecified */
   #define ATOMIC_LONG_LOCK_FREE     /* unspecified */
   #define ATOMIC_LLONG_LOCK_FREE    /* unspecified */

   #define ATOMIC_POINTER_LOCK_FREE  /* unspecified */
   #define ATOMIC_CHAR8_T_LOCK_FREE  /* unspecified */                \fB(4)\fP \fI(since C++20)\fP

   1,2) Determines if the atomic object pointed to by obj is implemented lock-free, as
   if by calling obj->is_lock_free(). In any given program execution, the result of the
   lock-free query is the same for all atomic objects of the same type.
   3,4) Expands to an integer constant expression with value
     * 0 for the built-in atomic types that are never lock-free,
     * 1 for the built-in atomic types that are sometimes lock-free,
     * 2 for the built-in atomic types that are always lock-free.

.SH Parameters

   obj - pointer to the atomic object to examine

.SH Return value

   true if *obj is a lock-free atomic, false otherwise.

.SH Notes

   All atomic types except for std::atomic_flag may be implemented using mutexes or
   other locking operations, rather than using the lock-free atomic CPU instructions.
   Atomic types are also allowed to be sometimes lock-free: for example, if only some
   subarchitectures support lock-free atomic access for a given type (such as the
   CMPXCHG16B instruction on x86-64), whether atomics are lock-free may not be known
   until runtime.

   The C++ standard recommends (but does not require) that lock-free atomic operations
   are also address-free, that is, suitable for communication between processes using
   shared memory.

.SH Example


// Run this code

 #include <atomic>
 #include <iostream>
 #include <utility>

 struct A { int a[100]; };
 struct B { int x, y; };

 int main()
 {
     std::atomic<A> a;
     std::atomic<B> b;
     std::cout << std::boolalpha
               << "std::atomic<A> is lock free? "
               << std::atomic_is_lock_free(&a) << '\\n'
               << "std::atomic<B> is lock free? "
               << std::atomic_is_lock_free(&b) << '\\n';
 }

.SH Possible output:

 std::atomic<A> is lock free? false
 std::atomic<B> is lock free? true

   Defect reports

   The following behavior-changing defect reports were applied retroactively to
   previously published C++ standards.

      DR    Applied to              Behavior as published              Correct behavior
                       atomic_is_lock_free was specified via pointers,
   LWG 3249 C++11      which                                           specified via
                       was ambiguous and might accept invalid pointer  atomic objects
                       values

.SH See also

   is_lock_free        checks if the atomic object is lock-free
                       \fI(public member function of std::atomic<T>)\fP
   atomic_flag         the lock-free boolean atomic type
   \fI(C++11)\fP             \fI(class)\fP
   is_always_lock_free indicates that the type is always lock-free
   \fB[static]\fP \fI(C++17)\fP    \fI(public static member constant of std::atomic<T>)\fP

   std::atomic_is_lock_free(std::shared_ptr) specializes atomic operations for
   (deprecated in C++20)                     std::shared_ptr
   (removed in C++26)                        \fI(function template)\fP
   C documentation for
   atomic_is_lock_free
   C documentation for
   ATOMIC_*_LOCK_FREE
